package last.project;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.Toast;


public class OptionScreen extends Activity {
	private Context cxt;
	private int MAX_X, MAX_Y;
	private static int BUTTON_TEXT_SIZE=FinalProjectActivity
	
	private Button MainMenu, ResetHighScores;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        cxt=this;
        setContentView(R.layout.optionlayout);
        
        setupVars();
        setuplayout();
        setupButtons();
	}
	private void setupVars() {
		MAX_X=FinalProjectActivity.MAX_X;
		MAX_Y=FinalProjectActivity.MAX_Y;
	}
	@SuppressWarnings("deprecation")
	private void setuplayout() {
		int BUTTON_TEXT_SIZE=18;
		AbsoluteLayout layout = (AbsoluteLayout) findViewById(R.id.AbsoluteLayout1);
		AbsoluteLayout.LayoutParams params;
		
		params = new AbsoluteLayout.LayoutParams(320, 65, MAX_X/2-160, MAX_Y/2);
		ResetHighScores = new Button(cxt);
		ResetHighScores.setText("Reset High Scores");
		ResetHighScores.setTextSize(BUTTON_TEXT_SIZE);
		layout.addView(ResetHighScores, params);
		
		params = new AbsoluteLayout.LayoutParams(320, 65, MAX_X/2-160, MAX_Y/2+70);
		MainMenu = new Button(cxt);
		MainMenu.setText("Main Menu");
		MainMenu.setTextSize(BUTTON_TEXT_SIZE);
		layout.addView(MainMenu, params);
	}
	private void setupButtons() {
		final DialogInterface.OnClickListener ConfirmedReset = new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface arg0, int arg1) {
				FinalProjectActivity.HSSystem.resetHighScores();
				Toast.makeText(cxt, "High scores have been reset.", Toast.LENGTH_SHORT).show();
			}
		};
		View.OnClickListener
			ResetHighScoreListener = new View.OnClickListener() {
				public void onClick(View v) {
					AlertDialog.Builder bob = new AlertDialog.Builder(cxt).setTitle((CharSequence) ("Confirm"));
					bob.setMessage((CharSequence) "Are you absolutely sure you want to delete all high scores? This cannot be undone.");
					bob.setNegativeButton((CharSequence) "Cancel", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface arg0, int arg1) {
						}
					});
					bob.setPositiveButton((CharSequence) "Reset Scores", ConfirmedReset);
					bob.show();
				}
			},
			MainMenuListener = new View.OnClickListener() {
				public void onClick(View v) {
					Intent tent = new Intent(cxt, FinalProjectActivity.class);
					cxt.startActivity(tent);
				}
			};
			
		ResetHighScores.setOnClickListener(ResetHighScoreListener);
		MainMenu.setOnClickListener(MainMenuListener);
	}
}
